package ibmetp.mis.controller.user;

import ibmetp.mis.common.Constants;
import ibmetp.mis.common.Message;
import ibmetp.mis.service.UserService;
import ibmetp.mis.serviceImpl.UserServiceImpl;
import ibmetp.mis.vo.User;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

/**
 * 用户登录
 * @author BIN
 *
 */
public class UserLoginServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    
    public UserLoginServlet() {
        super();
     
    }

	
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String userNo=request.getParameter("userNo");
		String pwd=request.getParameter("pwd");
		UserService us=new UserServiceImpl();
		User user=us.hasUser(userNo, pwd);
		if(user!=null)
		{
			request.getSession().setAttribute("userinfo",user);
			System.out.println("User Logined.."+user.getUserId());
			
		}
		else{
			//如果有返回消息，则将消息发回页面
			response.setCharacterEncoding(Constants.ENCODING_UTF8);
			response.getWriter().print(JSONObject.fromObject(new Message("登录失败")));
		}
		
	}

	
}
